#include <iostream>
#include <string>
#include <memory>
using namespace std;
//员工涨工资请求，用职责链实现
class RaisereQuest{
public:
  string _name;
  int _glary;
    RaisereQuest(string name,int glary)
    :_name(name)
    ,_glary(glary)
    
    {
    }
};
//类A不是抽象类，对于operation有自己的实现同时还要决定员工的请求要到哪里
class A{
    public:
        A * _a;
        //设置基类指针,让它指向派生类对象
        void  setnext(A * a){
            _a=a;
        }

        void runnext(RaisereQuest &rq){
            if(_a==nullptr){
                cout<<"涨薪被拒绝了"<<endl;
            }else{
                //用这个指针去调用派生类对象
                _a->operation(rq);
            }
        }


        virtual ~A(){}
        virtual void operation(RaisereQuest & rq)=0;
};
class depart:public A{
public:
    void operation(RaisereQuest & rq){
        if(rq._glary<1600){
            cout<<rq._name<<"的涨薪请求已被depart处理"<<endl;
        }else{
        //让上一级领导来处理
        runnext(rq);
        }
    }

};
class manager:public A{
public:
    void operation(RaisereQuest & rq){
    if(rq._glary<16000&&rq._glary>=1600){
            cout<<rq._name<<"的涨薪请求已被manager处理"<<endl;
        }else{
        //让上一级领导来处理
        _a->runnext(rq);
        }
    }

};

class CEO:public A{
public:
    void operation(RaisereQuest & rq){
        if(rq._glary<100000&&rq._glary>=16000){
            cout<<rq._name<<"的涨薪请求已被CEO处理"<<endl;
        }else{
            _a->runnext(rq);
        }
    }

};
void test(){
    RaisereQuest rq("zs",1600);
    unique_ptr<A> de(new depart());
    unique_ptr<A> ma(new manager());
    unique_ptr<A> ceo(new CEO());

    //用这个智能指针来连接下一个要执行的结点,就是给当前类的_a赋值
    //让_a指向要指向的下一个对象的operation
    de->setnext(ma.get());
    ma->setnext(ceo.get());
    ceo->setnext(nullptr); 
    de->operation(rq);
}
int main(int argc, char * argv[]){
    test();
    return 0;
}
